<?php

namespace app\admin\controller;

use app\admin\model\PohtoTagUser as PohtoTagUserModel;
use app\admin\validate\CommonnValidate;
use app\BaseController;

class PhotoTagUser extends BaseController
{
    protected $middleware = ['Auth'];
    public function list() {
        $params = $this->request->post(['current', 'size', 'photo_id', 'user_id']);
        $validate = new CommonnValidate();
        if (!$validate->scene('list')->check($params)) {
            return result()->fail($validate->getError(), 500);
        }
        $sql = new PohtoTagUserModel();
        $whereArr = [];
        if(isset($params['photo_id']) && $params['photo_id']) {
            $whereArr[] = ["photo_id", "=", $params['photo_id']];
        }
        if(isset($params['user_id']) && $params['user_id']) {
            $whereArr[] = ["user_id", "=", $params['user_id']];
        }
        $list = $sql
            ->where($whereArr)
            ->with(['userInfo', 'photoInfo'])
            ->order('create_at desc')
            ->paginate([
                'list_rows'=> request()->param('size'),
                'page' => request()->param('current'),
            ]);
        return result()->success($list);
    }
}